package com.arch.bigdata.hbase;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.util.Bytes;

import java.io.IOException;

/**
 * @author pizhihui
 * @date 2024-06-05 13:05
 */
public class HbaseReadDemo {


    public static void main(String[] args) throws IOException {


        Configuration conf = HBaseConfiguration.create();


        Connection connection = ConnectionFactory.createConnection(conf);
        Table table = connection.getTable(TableName.valueOf("test"));
        try {

            Get get = new Get("189107817222".getBytes());
            get.addColumn("info".getBytes(), "k1".getBytes());
            Result result = table.get(get);

            for (Cell cell : result.listCells()) {

                System.out.println("family: " + Bytes.toString(CellUtil.cloneFamily(cell)));
                System.out.println("qualifier: " + Bytes.toString(CellUtil.cloneQualifier(cell)));
                System.out.println("value: " + Bytes.toString(CellUtil.cloneValue(cell)));
            }

        } finally {
            table.close();
            connection.close();
        }

    }

}
